/*
Copyright [2012] [Maria Eugenia Malagamba]
Copyright [2012] [Leandro Pellegrino]
Copyright [2012] [Julia Gambuzzi]
Copyright [2012] [Ignacio Capodanno]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include "Label.h"


Label::Label(string texto)
{
	this->texto = texto;
	this->fuente =  TTF_OpenFont( "ARIAL.ttf", 26 );
	
	//Color de la fuente
	this->color.b = 0x00;
	this->color.g = 0x00;
	this->color.r = 0x00;

	//Render a new text surface
    this->imagenTexto = TTF_RenderText_Solid( this->fuente, this->texto.c_str(), this->color );
	
	this->posicion.w = this->imagenTexto->w;
	this->posicion.h = this->imagenTexto->h;

}

Label::Label(int x, int y,string texto, int tamanioFuente){
	
	this->posicion.x = x;
	this->posicion.y = y;
	this->texto = texto;
	this->fuente =  TTF_OpenFont( "ARIAL.ttf", tamanioFuente );
	
	//Color de la fuente
	this->color.b = 0x00;
	this->color.g = 0x00;
	this->color.r = 0x00;

	
	if(texto == ""){
		texto = "nombre";
	}
	//Render a new text surface
    this->imagenTexto = TTF_RenderText_Solid( this->fuente, texto.c_str(), this->color );

	this->posicion.w = this->imagenTexto->w;
	this->posicion.h = this->imagenTexto->h;
}

Label::Label(int x, int y,string texto, int tamanioFuente,string nombreDeLaFuente){
	
	this->posicion.x = x;
	this->posicion.y = y;
	this->texto = texto;
	this->fuente =  TTF_OpenFont( nombreDeLaFuente.c_str(), tamanioFuente );
	
	//Color de la fuente
	this->color.b = 0x00;
	this->color.g = 0x00;
	this->color.r = 0x00;

	
	if(texto == ""){
		texto = "nombre";
	}
	//Render a new text surface
    this->imagenTexto = TTF_RenderText_Solid( this->fuente, texto.c_str(), this->color );

	this->posicion.w = this->imagenTexto->w;
	this->posicion.h = this->imagenTexto->h;
}

void Label::centrar(int anchoLienzo, int altoLienzo){

	this->posicion.x += ( anchoLienzo - this->imagenTexto->w ) / 2;
	this->posicion.y += ( altoLienzo - this->imagenTexto->h ) / 2;
}

void Label::mostrar(SDL_Surface* lienzo)
{            
    if( this->imagenTexto != NULL )
    {
		SDL_BlitSurface(this->imagenTexto,NULL,lienzo,&posicion);
	}
}

void Label::cambiarTexto(string nuevoTexto){

	//limpio el texto anterior
	this->texto = "                                                    ";
	//asigno el texto nuevo
	this->texto = nuevoTexto;

	SDL_FreeSurface(this->imagenTexto);

	//Render a new text surface
    this->imagenTexto = TTF_RenderText_Solid( this->fuente, this->texto.c_str(), this->color );

	this->posicion.w = this->imagenTexto->w;
	this->posicion.h = this->imagenTexto->h;

}
string Label::getTexto(){
	return this->texto;
}

int Label::getPosicionX(){
	return this->posicion.x;
}

int Label::getPosicionY(){
	return this->posicion.y;
}

void Label::setPosicionX(int x){
	this->posicion.x = x;
}

void Label::setPosicionY(int y){
	this->posicion.y = y;
}

int Label::getAlto(){
	return imagenTexto->h;
}
int Label::getAncho(){
	return imagenTexto->w;
}

Label::~Label(void)
{
	TTF_CloseFont( this->fuente);

	  //libero la superficie
    SDL_FreeSurface( this->imagenTexto );
    
    //Disable Unicode
    SDL_EnableUNICODE( SDL_DISABLE );  

}

